<template>
  <n-layout-sider
      :collapsed-width="64"
      :width="240"
      :native-scrollbar="false"
      bordered
      show-trigger
      collapse-mode="width"
      class="x-layout-sider"
  >
    <div class="user-info">
      <div class="icon"></div>
      <div class="name">
        <div class="text-lg store-name">迷你商城</div>
        <div class="text-lg username">
          <div>{{adminStore.adminInfo.nickName}}</div>
          <n-button class="ml-5" ghost text @click="logout">登出</n-button>
        </div>
      </div>
    </div>
    <n-menu
        :root-indent="16"
        :indent="0"
        :collapsed-width="64"
        :options="adminStore.menuOptions"
        :default-expand-all="true"
        :watch-props="['defaultExpandedKeys']"
        :default-value="route.name"
        class="x-menu"
    />
  </n-layout-sider>
</template>

<script setup>
import {NButton, NLayoutSider, NMenu} from "naive-ui";
import useAdminStore from "@/store/admin";
import {useRouter, useRoute} from "vue-router";
import {removeToken} from "@/store/local";

const route = useRoute()
const router = useRouter()
const adminStore = useAdminStore()

function logout() {
  removeToken();
  router.replace({name: 'Login'})
}
</script>

<style lang="scss" scoped>
.x-layout-sider {
  border-top: 1px solid #f8f8f8;
  font-size: 12px;
  text-align: center;
  padding: 10px 0;
  .user-info {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f8f8f8;
    padding-bottom: 5px;
    .icon {
      width: 40px;
      height: 40px;
      margin: 0 10px 0 20px;
      border-radius: 50%;
      background: #000;
    }
    .store-name {
      font-weight: bold;
    }
    .username {
      display: flex;
    }
  }
}
.x-menu {
  :deep(.n-menu-item) {
    margin-bottom: 10px;
  }

  :deep(.n-submenu-children) {
    display: flex;
    flex-wrap: wrap;
    font-size: 12px;
    .n-menu-item-content {
      height: 30px;
    }
    .n-menu-item {
      width: 50%;
      height: 30px;
      margin-top: 0;
      text-align: center;
    }
  }
}
</style>